import ClassModel from '../models/Role' //班级管理服务
export default class ClassService {    // 获取所有班级 
  async findClassList() {
    try {
      return ClassModel.findAll({
        attributes: ['id', 'className', 'classCode', 'headTeacherId']
      });
    } catch (err) {
      throw (err);
    }
  }
  //获取单个班级
  async findClassById(classId: string) {
    try {
      return ClassModel.findOne({
        attributes: ['id', 'className', 'classCode', 'headTeacherId'],
        where: { id: classId }
      });
    } catch (err) { throw (err); }
  }
  async deleteClass(classId: string) { 
    try {
      return await ClassModel.destroy({
        where: { id: classId }
      });
    } catch (err) {
      throw (err);
    }
  }
  async editClass(classObj: any) {
    try {
      return await ClassModel.update(classObj, {
        where: { id: classObj.id },
        individualHooks: true
      });
    } catch (err) {
      throw (err);
    }
  }
  async addClass(classObj: any) {
    try {
      return await ClassModel.create(classObj);
    } catch (err) {
      throw (err);
    }
  }
}